import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.Person
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.NavigationBarItemDefaults
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import com.google.accompanist.insets.navigationBarsPadding
import icu.bughub.app.app.model.entity.NavigationItem
import icu.bughub.app.app.ui.screens.MineScreen
import icu.bughub.app.app.ui.screens.StudyScreen
import icu.bughub.app.app.ui.screens.TaskScreen


/**
 * 主界面 底部导航栏
 */
@Composable
fun MainFrame(
    onNavigateToArticleDetail: () -> Unit = {},
    onNavigateToVideoDetail: () -> Unit = {},
    onNavigateToStudyHistory: () -> Unit = {}
) {
    var currentNavigationIndex by remember { mutableIntStateOf(0) }
    val items = listOf(
        NavigationItem("学习", icon = Icons.Default.Home),
        NavigationItem("任务", icon = Icons.Default.Menu),
        NavigationItem("我的", icon = Icons.Default.Person),
    )

    Scaffold(bottomBar = {
        NavigationBar(
            containerColor = MaterialTheme.colorScheme.surface,
            modifier = Modifier.navigationBarsPadding(bottom = false)
        ) {
            items.forEachIndexed { index, item ->
                NavigationBarItem(
                    icon = { Icon(imageVector = item.icon, contentDescription = null) },
                    label = { Text(item.title) },
                    selected = currentNavigationIndex == index,
                    onClick = { currentNavigationIndex = index },
                    colors = NavigationBarItemDefaults.colors(
                        selectedIconColor = Color(color = 0xFFF149ee7),
                        selectedTextColor = Color(color = 0xFFF149ee7),
                        indicatorColor = Color.Transparent, //去除选中背景色
                        unselectedIconColor = Color(0xff999999),
                        unselectedTextColor = Color(0xff999999),
                    )
                )
            }
        }

    }) { innerPadding ->
        Box(
            modifier = Modifier.padding(bottom = innerPadding.calculateBottomPadding())
        ) {
            when (currentNavigationIndex) {
                0 -> StudyScreen(
                    onNavigateToArticleDetail = onNavigateToArticleDetail,
                    onNavigateToVideoDetail = onNavigateToVideoDetail,
                    onNavigateToStudyHistory = onNavigateToStudyHistory
                )

                1 -> TaskScreen()
                2 -> MineScreen()
            }
        }
    }

}




